#include <fstream>
#include <string.h>
#include <sys/stat.h>
#include <arpa/inet.h>

#include "Constant.h"
#include "NetworkTools.h"
#include "ThreadPool.h"
#include "SimpleThreadFactory.h"

class Server {
public:
    virtual ~Server();

private:
    static int id;

    static ThreadPool *pool;

    static bool isCompleteShunt;

    static pthread_mutex_t mutex;

public:
    static void startServer();

    static void endServer();

    static int getUserId();

private:
    static void createDataFile();

    static int getUserIdFromFile();

    static bool saveUserIdToFile(int userId);

    static void changeIntToChar(int userId, int &length, char buffer[]);

private:
    static void serverWorkThread(void *args);

    static void serverAcceptTaskThread(void *args);

    static void serverCommunicateTaskThread(void *args);
};